<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MySQL LIKE查询优化指南 | Java技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            border-left: 4px solid #2563eb;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .tooltip:hover .tooltip-text {
            visibility: visible;
            opacity: 1;
        }
        .anchor {
            display: block;
            position: relative;
            top: -80px;
            visibility: hidden;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-2/3 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 serif">MySQL LIKE查询<br>性能优化完全指南</h1>
                    <p class="text-xl mb-8 opacity-90">从系统崩溃到毫秒响应 - 专业DBA不会告诉你的优化秘籍</p>
                    <div class="bg-black bg-opacity-30 p-4 rounded-lg mb-8">
                        <p class="flex items-start"><i class="fas fa-exclamation-triangle text-yellow-400 mt-1 mr-2"></i> 
                        <span>上周我们系统崩了 - 就因产品经理非要加个<code class="bg-gray-800 px-2 py-1 rounded mx-1">%爆款%</code>搜索！用户一搜『2025新款』，MySQL直接CPU 100%躺平，每秒丢单300+！</span></p>
                    </div>
                    <div class="flex flex-wrap gap-4">
                        <a href="#why" class="bg-white text-blue-800 hover:bg-blue-100 px-6 py-3 rounded-lg font-medium transition duration-300">
                            <i class="fas fa-search mr-2"></i>问题诊断
                        </a>
                        <a href="#solutions" class="bg-blue-700 hover:bg-blue-800 px-6 py-3 rounded-lg font-medium transition duration-300">
                            <i class="fas fa-tools mr-2"></i>解决方案
                        </a>
                    </div>
                </div>
                <div class="md:w-1/3">
                    <div class="bg-white bg-opacity-10 p-2 rounded-xl border border-white border-opacity-20">
                        <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1743667922610-a70627f3-0471-49b1-97c1-24fdeb82b2df.png" 
                             alt="MySQL性能优化" class="rounded-lg shadow-xl w-full">
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto py-12 px-4">
        <!-- Why LIKE is bad -->
        <section id="why" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-bug text-red-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">为什么LIKE查询是性能杀手</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-10">
                <div class="bg-gray-800 text-white px-6 py-3 flex items-center">
                    <i class="fas fa-flask mr-2"></i>
                    <h3 class="font-mono">实验：百万商品数据测试</h3>
                </div>
                <div class="p-6">
                    <div class="code-block text-gray-200 p-4 rounded mb-6 overflow-x-auto">
                        <pre><code>-- 测试表结构
CREATE TABLE products (
    id INT PRIMARY KEY AUTO_INCREMENT,
    title VARCHAR(200) NOT NULL,
    description TEXT,
    INDEX idx_title (title(20))
) CHARSET=utf8mb4;

-- 执行模糊查询（耗时2.8秒）
SELECT * FROM products 
WHERE title LIKE '%新款%' 
LIMIT 100;</code></pre>
                    </div>
                    
                    <h4 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <span class="w-6 h-6 bg-blue-100 text-blue-800 rounded-full flex items-center justify-center mr-2">1</span>
                        执行流程拆解
                    </h4>
                    
                    <div class="grid md:grid-cols-3 gap-6 mb-8">
                        <div class="bg-blue-50 p-4 rounded-lg border border-blue-100">
                            <div class="text-blue-800 mb-2 flex items-center">
                                <i class="fas fa-list-ol mr-2"></i>
                                <span class="font-medium">全表扫描</span>
                            </div>
                            <p class="text-gray-700">遍历全表所有记录的title字段（100万行）</p>
                        </div>
                        <div class="bg-purple-50 p-4 rounded-lg border border-purple-100">
                            <div class="text-purple-800 mb-2 flex items-center">
                                <i class="fas fa-search mr-2"></i>
                                <span class="font-medium">字符串匹配</span>
                            </div>
                            <p class="text-gray-700">逐行进行字符串匹配（类似Java的String.contains()）</p>
                        </div>
                        <div class="bg-amber-50 p-4 rounded-lg border border-amber-100">
                            <div class="text-amber-800 mb-2 flex items-center">
                                <i class="fas fa-clock mr-2"></i>
                                <span class="font-medium">低效查询</span>
                            </div>
                            <p class="text-gray-700">即使找到100条匹配项，也要扫描完整个表</p>
                        </div>
                    </div>
                    
                    <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 rounded-r-lg flex">
                        <i class="fas fa-lightbulb text-yellow-500 text-xl mr-3 mt-1"></i>
                        <p>就像在图书馆逐页翻完全部藏书找某个关键词，不管这个关键词出现在第几页！</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Common Mistakes -->
        <section id="mistakes" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-yellow-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-exclamation-triangle text-yellow-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">四大常见错误写法<br><span class="text-xl text-gray-600">(你至少中过两招)</span></h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6">
                <!-- Mistake 1 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                    <div class="bg-red-600 text-white px-6 py-3 flex items-center">
                        <i class="fas fa-times-circle mr-2"></i>
                        <h3 class="font-medium">双百分号暴击</h3>
                    </div>
                    <div class="p-6">
                        <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                            <pre><code>-- 全表扫描（最差情况）
SELECT * FROM products 
WHERE description LIKE '%清凉%夏季%';</code></pre>
                        </div>
                        <div class="flex items-start text-red-600">
                            <i class="fas fa-heartbeat mt-1 mr-2"></i>
                            <p>这种写法会让MySQL进行完整的全表扫描，性能极差</p>
                        </div>
                    </div>
                </div>
                
                <!-- Mistake 2 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                    <div class="bg-orange-500 text-white px-6 py-3 flex items-center">
                        <i class="fas fa-exclamation-circle mr-2"></i>
                        <h3 class="font-medium">索引失效陷阱</h3>
                    </div>
                    <div class="p-6">
                        <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                            <pre><code>-- 即使有title索引也无效
SELECT * FROM products 
WHERE title LIKE '%短袖' 
ORDER BY price DESC;</code></pre>
                        </div>
                        <div class="flex items-start text-orange-600">
                            <i class="fas fa-search-minus mt-1 mr-2"></i>
                            <p>前导通配符%会导致索引失效，排序操作会加剧性能问题</p>
                        </div>
                    </div>
                </div>
                
                <!-- Mistake 3 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                    <div class="bg-amber-500 text-white px-6 py-3 flex items-center">
                        <i class="fas fa-database mr-2"></i>
                        <h3 class="font-medium">大字段轰炸</h3>
                    </div>
                    <div class="p-6">
                        <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                            <pre><code>-- 对TEXT类型字段模糊查询
SELECT * FROM blog 
WHERE content LIKE '%数据库优化%';</code></pre>
                        </div>
                        <div class="flex items-start text-amber-600">
                            <i class="fas fa-weight-hanging mt-1 mr-2"></i>
                            <p>TEXT字段内容量大，模糊查询会消耗大量内存和CPU资源</p>
                        </div>
                    </div>
                </div>
                
                <!-- Mistake 4 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                    <div class="bg-purple-600 text-white px-6 py-3 flex items-center">
                        <i class="fas fa-layer-group mr-2"></i>
                        <h3 class="font-medium">无节制分页</h3>
                    </div>
                    <div class="p-6">
                        <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                            <pre><code>-- 深分页+模糊查询双重暴击
SELECT * FROM products 
WHERE title LIKE '%连衣裙%' 
LIMIT 100000, 20;</code></pre>
                        </div>
                        <div class="flex items-start text-purple-600">
                            <i class="fas fa-bomb mt-1 mr-2"></i>
                            <p>某社交平台因此导致主库CPU持续100%，最终不得不杀掉慢查询</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Business Layer Optimization -->
        <section id="business" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-chart-line text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">业务层优化策略</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <span class="w-8 h-8 bg-blue-100 text-blue-800 rounded-full flex items-center justify-center mr-3">1</span>
                        搜索条件限制
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>最小搜索长度：3个字符起</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>禁用特殊符号：<code>*_%</code>等</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>关键词白名单机制</span>
                        </li>
                    </ul>
                    
                    <div class="mt-6">
                        <h4 class="font-medium mb-2 text-gray-800">Spring Boot参数校验示例：</h4>
                        <div class="code-block text-gray-200 p-4 rounded overflow-x-auto">
                            <pre><code>@GetMapping("/search")
public ResponseEntity&lt;?&gt; searchProducts(
    @RequestParam @Size(min=2, max=20) String keyword) {
    // 业务逻辑
}</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <span class="w-8 h-8 bg-purple-100 text-purple-800 rounded-full flex items-center justify-center mr-3">2</span>
                        缓存预热策略
                    </h3>
                    <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                        <pre><code>-- 热点关键词缓存表
CREATE TABLE hot_keywords (
    keyword VARCHAR(50) PRIMARY KEY,
    product_ids JSON,
    expire_time DATETIME
);

-- 每日凌晨预计算
INSERT INTO hot_keywords
SELECT 
    keyword, 
    JSON_ARRAYAGG(id),
    NOW() + INTERVAL 1 DAY
FROM search_logs
GROUP BY keyword
HAVING COUNT(*) &gt; 1000;</code></pre>
                    </div>
                    <div class="flex items-start text-purple-600">
                        <i class="fas fa-bolt mt-1 mr-2"></i>
                        <p>通过预计算热点搜索词，可以大幅减少实时查询压力</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Database Layer Optimization -->
        <section id="solutions" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-database text-green-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">数据库层优化方案</h2>
            </div>
            
            <div class="space-y-12">
                <!-- Solution 1 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="bg-blue-600 text-white px-6 py-3 flex items-center">
                        <i class="fas fa-arrow-up mr-2"></i>
                        <h3 class="font-medium">前缀索引优化</h3>
                    </div>
                    <div class="p-6">
                        <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                            <pre><code>ALTER TABLE products 
ADD INDEX idx_title_prefix (title(10));

-- 查询示例（可利用索引）
SELECT * FROM products 
WHERE title LIKE '夏季新款%'; -- 注意左匹配</code></pre>
                        </div>
                        <div class="grid md:grid-cols-2 gap-6">
                            <div>
                                <h4 class="font-medium mb-2 text-gray-800 flex items-center">
                                    <i class="fas fa-thumbs-up text-blue-500 mr-2"></i>
                                    优点
                                </h4>
                                <ul class="text-gray-700 space-y-2">
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                        <span>简单易实现，无需修改业务代码</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                        <span>对左匹配查询性能提升显著</span>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                <h4 class="font-medium mb-2 text-gray-800 flex items-center">
                                    <i class="fas fa-thumbs-down text-red-500 mr-2"></i>
                                    缺点
                                </h4>
                                <ul class="text-gray-700 space-y-2">
                                    <li class="flex items-start">
                                        <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                                        <span>仍然不支持前导通配符查询</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                                        <span>需要合理选择前缀长度</span>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Solution 2 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="bg-purple-600 text-white px-6 py-3 flex items-center">
                        <i class="fas fa-exchange-alt mr-2"></i>
                        <h3 class="font-medium">倒排索引方案</h3>
                    </div>
                    <div class="p-6">
                        <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                            <pre><code>-- 创建关键词映射表
CREATE TABLE product_keywords (
    product_id INT,
    keyword VARCHAR(20),
    PRIMARY KEY (product_id, keyword),
    INDEX idx_keyword (keyword)
);

-- 查询改写
SELECT p.* 
FROM products p
JOIN product_keywords k ON p.id = k.product_id
WHERE k.keyword = '新款';</code></pre>
                        </div>
                        <div class="bg-blue-50 border-l-4 border-blue-400 p-4 rounded-r-lg mb-4">
                            <p class="font-medium text-blue-800">适用场景：</p>
                            <p class="text-gray-700">关键词数量有限且可枚举的垂直搜索场景，如商品标签、分类等</p>
                        </div>
                    </div>
                </div>
                
                <!-- Solution 3 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="bg-green-600 text-white px-6 py-3 flex items-center">
                        <i class="fas fa-magic mr-2"></i>
                        <h3 class="font-medium">虚拟列魔法（MySQL 5.7+）</h3>
                    </div>
                    <div class="p-6">
                        <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                            <pre><code>ALTER TABLE products
ADD COLUMN title_prefix VARCHAR(20) GENERATED ALWAYS AS (LEFT(title, 20)) VIRTUAL,
ADD INDEX idx_title_prefix (title_prefix);

-- 优化后查询
SELECT * FROM products 
WHERE title_prefix LIKE '夏季%';</code></pre>
                        </div>
                        <div class="flex items-start text-green-600">
                            <i class="fas fa-lightbulb mt-1 mr-2"></i>
                            <p>利用MySQL的虚拟列特性，可以创建基于函数计算的索引，优化特定模式的模糊查询</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Ultimate Solution -->
        <section class="mb-20">
            <div class="bg-gradient-to-r from-blue-600 to-purple-600 rounded-xl shadow-lg overflow-hidden">
                <div class="px-6 py-4 text-white">
                    <h2 class="text-2xl font-bold mb-2 serif">终极解决方案</h2>
                    <p class="opacity-90">当数据量超过千万级时，必须上<b>专业搜索引擎</b></p>
                </div>
                <div class="bg-white bg-opacity-90 p-6">
                    <div class="overflow-x-auto">
                        <table class="min-w-full bg-white">
                            <thead>
                                <tr class="bg-gray-100">
                                    <th class="py-3 px-4 text-left text-gray-700 font-medium">方案</th>
                                    <th class="py-3 px-4 text-left text-gray-700 font-medium">响应时间</th>
                                    <th class="py-3 px-4 text-left text-gray-700 font-medium">功能支持</th>
                                    <th class="py-3 px-4 text-left text-gray-700 font-medium">维护成本</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-gray-200">
                                <tr>
                                    <td class="py-3 px-4">MySQL</td>
                                    <td class="py-3 px-4">200ms~5s</td>
                                    <td class="py-3 px-4">基础模糊查询</td>
                                    <td class="py-3 px-4">低</td>
                                </tr>
                                <tr class="bg-blue-50">
                                    <td class="py-3 px-4 font-medium">Elasticsearch</td>
                                    <td class="py-3 px-4">10~50ms</td>
                                    <td class="py-3 px-4">分词/同义词/拼音搜索</td>
                                    <td class="py-3 px-4">中</td>
                                </tr>
                                <tr>
                                    <td class="py-3 px-4">MeiliSearch</td>
                                    <td class="py-3 px-4">5~30ms</td>
                                    <td class="py-3 px-4">即时搜索</td>
                                    <td class="py-3 px-4">低</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    
                    <div class="mt-8">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">某电商平台迁移案例</h3>
                        <ol class="list-decimal pl-5 space-y-2 text-gray-700">
                            <li>使用Logstash同步MySQL数据到ES</li>
                            <li>搜索接口改用ES查询</li>
                            <li>响应时间从2.3秒降至28ms</li>
                        </ol>
                        
                        <div class="mt-6">
                            <h4 class="font-medium mb-2 text-gray-800">Spring Boot集成ES示例：</h4>
                            <div class="code-block text-gray-200 p-4 rounded overflow-x-auto">
                                <pre><code>@Autowired
private ElasticsearchOperations operations;

public List&lt;Product&gt; search(String keyword) {
    NativeSearchQuery query = new NativeSearchQueryBuilder()
        .withQuery(QueryBuilders.matchQuery("title", keyword))
        .build();
    return operations.search(query, Product.class)
        .get().map(SearchHit::getContent).collect(Collectors.toList());
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Pitfalls -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-skull-crossbones text-red-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">这些细节让你前功尽弃</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6">
                <!-- Pitfall 1 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">字符集陷阱</h3>
                    <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                        <pre><code>-- utf8mb4的排序规则影响索引
ALTER TABLE products 
MODIFY title VARCHAR(200) 
CHARACTER SET utf8mb4 
COLLATE utf8mb4_0900_ai_ci;</code></pre>
                    </div>
                    <div class="flex items-start text-gray-700">
                        <i class="fas fa-info-circle text-blue-500 mt-1 mr-2"></i>
                        <p>不同的字符集和排序规则会影响索引的使用效率和匹配精度</p>
                    </div>
                </div>
                
                <!-- Pitfall 2 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">隐式类型转换</h3>
                    <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                        <pre><code>-- 错误示例（price是DECIMAL类型）
SELECT * FROM products 
WHERE title LIKE CONCAT('%', 123, '%');</code></pre>
                    </div>
                    <div class="flex items-start text-gray-700">
                        <i class="fas fa-exclamation text-red-500 mt-1 mr-2"></i>
                        <p>类型不匹配会导致索引失效，引发全表扫描</p>
                    </div>
                </div>
                
                <!-- Pitfall 3 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">索引长度选择</h3>
                    <div class="code-block text-gray-200 p-4 rounded mb-4 overflow-x-auto">
                        <pre><code>-- 计算不同长度的区分度
SELECT 
    COUNT(DISTINCT LEFT(title,10))/COUNT(*) AS ratio10,
    COUNT(DISTINCT LEFT(title,20))/COUNT(*) AS ratio20 
FROM products;</code></pre>
                    </div>
                    <div class="flex items-start text-gray-700">
                        <i class="fas fa-ruler text-green-500 mt-1 mr-2"></i>
                        <p>索引长度过小会降低区分度，过大则浪费存储空间</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Final Words -->
        <section class="bg-amber-50 border-l-4 border-amber-400 p-6 rounded-r-lg mb-20">
            <div class="flex items-start">
                <i class="fas fa-quote-left text-amber-600 text-3xl mr-4 mt-1"></i>
                <div>
                    <h2 class="text-2xl font-bold text-gray-800 mb-4 serif">最后说句得罪人的话</h2>
                    <p class="text-gray-700 mb-4">我见过最离谱的LIKE查询是<code class="bg-amber-100 text-amber-800 px-2 py-1 rounded">WHERE description LIKE '%%'</code>——这相当于要把整个数据库装进ResultSet！记住三个原则：</p>
                    <ol class="list-decimal pl-5 space-y-2 text-gray-700 mb-4">
                        <li><b>能不用LIKE就不用</b>（优先等值查询）</li>
                        <li><b>必须用时控制查询范围</b>（时间范围/分类过滤）</li>
                        <li><b>超过百万数据立即考虑搜索引擎</b></li>
                    </ol>
                    <p class="text-gray-700 font-medium">你的系统里还有多少这样的定时炸弹？不妨用这个脚本检测一下：</p>
                    <div class="code-block text-gray-200 p-4 rounded mt-4 overflow-x-auto">
                        <pre><code>-- 查找慢查询中的LIKE语句
SELECT * FROM mysql.slow_log 
WHERE query_text LIKE '%LIKE%'
AND exec_time > 2;</code></pre>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10 px-4">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">Java技术小馆</h3>
                    <p class="text-gray-400">专业的技术分享平台</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition duration-300">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                <p>© 2023 Java技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true
            }
        });
    </script>
</body>
</html>